import {Pipe, PipeTransform} from '@angular/core';

@Pipe({
  name: 'badgePipe'
})
export class BadgePipe implements PipeTransform {
  constructor() {
  }

  transform(value: any, values: any[], colors: any[]): any {

    if (values.length !== colors.length) {
      throw new Error(`values.length != colors.length`);
    }

    const text = value;
    let cssClass;

    for (let i = 0; i < values.length; i++) {
      if (value === values[i]) {
        cssClass = colors[i];
      }
    }

    return {'cssClass': cssClass, 'text': text};
  }
}
